package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.model.auto.EntCollect;
import com.fc.test.model.auto.EntCollectExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.StuInfoMapper;
import com.fc.test.model.auto.StuInfo;
import com.fc.test.model.auto.StuInfoExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 学生个人信息 StuInfoService
 * @Title: StuInfoService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:22:43  
 **/
@Service
public class StuInfoService implements BaseService<StuInfo, StuInfoExample>{
	@Autowired
	private StuInfoMapper stuInfoMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<StuInfo> list(Tablepar tablepar,StuInfo record){
	        StuInfoExample testExample=new StuInfoExample();
	        testExample.createCriteria().andLikeQuery(record);
	        testExample.setOrderByClause("sid ASC");
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<StuInfo> list= stuInfoMapper.selectByExample(testExample);
	        PageInfo<StuInfo> pageInfo = new PageInfo<StuInfo>(list);
	        return  pageInfo;
	 }

	public PageInfo<StuInfo> listForSys(Tablepar tablepar, StuInfo record){
		StuInfoExample testExample=new StuInfoExample();
		testExample.createCriteria().andLikeQuery(record);
		testExample.setOrderByClause("sid ASC");
		if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
			testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<StuInfo> list= stuInfoMapper.selectByExample(testExample);
		PageInfo<StuInfo> pageInfo = new PageInfo<StuInfo>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			StuInfoExample example=new StuInfoExample();
			example.createCriteria().andSidIn(stringB);
			return stuInfoMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public StuInfo selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return stuInfoMapper.selectByPrimaryKey(id1);
				
	}


	//此处屏蔽传入密码，拒绝更新
	@Override
	public int updateByPrimaryKeySelective(StuInfo record) {
		return stuInfoMapper.updateByPrimaryKeySelective(record);
	}

	public int updatePasswordByPrimaryKeySelective(String id, String password) {
		Integer id1 = Integer.valueOf(id);

		return stuInfoMapper.updatePasswordByPrimaryKeySelective(id1, password);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(StuInfo record) {
				
		record.setSid(null);
		
				
		return stuInfoMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(StuInfo record, StuInfoExample example) {
		
		return stuInfoMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(StuInfo record, StuInfoExample example) {
		
		return stuInfoMapper.updateByExample(record, example);
	}

	@Override
	public List<StuInfo> selectByExample(StuInfoExample example) {
		
		return stuInfoMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(StuInfoExample example) {
		
		return stuInfoMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(StuInfoExample example) {
		
		return stuInfoMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param stuInfo
	 * @return
	 */
	public int checkNameUnique(StuInfo stuInfo){
		StuInfoExample example=new StuInfoExample();
		example.createCriteria().andNameEqualTo(stuInfo.getName());
		List<StuInfo> list=stuInfoMapper.selectByExample(example);
		return list.size();
	}


	public StuInfo findByAccount(String account) {
		return stuInfoMapper.selectByAccount(account);
	}
}
